package com.neuedu.pojo;

import lombok.Data;

/**
 * 统一返回结果
 * @author 屈博
 * @email qubome@aliyun.com
 * @Date 2024/6/4 21:18
 */
@Data
public class Result<T> {
    // 响应的结果状态码
    private Integer code;
    // 响应的结果信息
    private String message;
    // 响应的数据
    private T data;
    // 分页的总记录数
    private Long total;

    // 封装基本操作成功的方法
    public static <T> Result<T> success() {
        return success(2000 , null , "操作成功" , 0L);
    }
    public static <T> Result<T> success(String message) {
        return success(2000 , null , message , 0L);
    }
    public static <T> Result<T> success(T data) {
        return success(2000 , data , "操作成功" , 0L);
    }
    public static <T> Result<T> success(T data,String message) {
        return success(2000 , data , message , 0L);
    }
    public static <T> Result<T> success(T data,String message,Long total) {
        return success(2000 , data , message , total);
    }
    public static <T> Result<T> success(Integer code , T data,String message) {
        return success(code , data , message , 0L);
    }
    public static <T> Result<T> success(Integer code , T data,String message , Long total) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        result.setTotal(total);
        return result;
    }

    // 封装操作失败的常用方法
    public static <T> Result<T> fail() {
        return fail(5000 , null , "操作失败" , 0L);
    }
    public static <T> Result<T> fail(String message) {
        return fail(5000 , null , message , 0L);
    }
    public static <T> Result<T> fail(T data) {
        return fail(5000 , data , "操作失败" , 0L);
    }
    public static <T> Result<T> fail(T data,String message) {
        return fail(5000 , data , message , 0L);
    }
    public static <T> Result<T> fail(Integer code , T data,String message) {
        return fail(code , data , message , 0L);
    }
    public static <T> Result<T> fail(Integer code , T data,String message , Long total) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        result.setTotal(total);
        return result;
    }
}
